package com.newtouch.bxzs.enterprise.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import com.newtouch.bxzs.enterprise.config.MyLog;
import com.newtouch.bxzs.enterprise.model.bo.*;
import com.newtouch.bxzs.enterprise.model.vo.*;
import com.newtouch.bxzs.enterprise.service.ActivityService;
import com.newtouch.bxzs.enterprise.service.CustomerInventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 营销活动controller类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021年1月29日</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 * 
 * @author Amour
 * 
 * @version 1.0.0
 * @since 1.0.0.
 */
@Api(tags = "营销活动")
@RestController
@RequestMapping(value = "/activityController")
@SuppressWarnings("unchecked")
public class ActivityController {

	/** 静态变量：系统日志 */
	private static final Log logger = LogFactory.getLog(ActivityController.class);

	@Autowired
	ActivityService activityService;

	@Autowired
    CustomerInventoryService customerInventoryService;

	@ApiOperation(value = "获取营销活动信息列表")
	@PostMapping("/getActivityList")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/getActivityList", userOperationType = 4, userOperationSummary = "获取营销活动信息列表")
	BaseResponse<IPage<ActivityBO>> getActivityList(@RequestBody ActivityVO activityVO) {
		logger.info("获取营销活动信息列表");
		return RespGenerator.returnOK(activityService.getActivityList(activityVO));
	}

	@ApiOperation(value = "获取营销活动信息列表,查询业绩时使用")
	@PostMapping("/getAchievementActivityList")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/getAchievementActivityList", userOperationType = 4, userOperationSummary = "获取营销活动信息列表,查询业绩时使用")
	BaseResponse<IPage<ActivityBO>> getAchievementActivityList(@RequestBody ActivityAchievementVO activityVO) {
		logger.info("获取营销活动信息列表");
		return RespGenerator.returnOK(activityService.getAchievementActivityList(activityVO));
	}

	@ApiOperation(value = "获取营销活动详情")
	@GetMapping("/getActivityDetail")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/getActivityDetail", userOperationType = 4, userOperationSummary = "获取营销活动详情")
	BaseResponse<ActivityDetailBO> getActivityDetail(
			@RequestParam("activityId") @ApiParam(value = "营销活动id", required = true) String activityId,
			@RequestParam("managerFlag") @ApiParam(value = "是否为管理岗", required = true) Boolean managerFlag) {
		logger.info("获取营销活动详情");
		return RespGenerator.returnOK(activityService.getActivityDetail(activityId, managerFlag));
	}

	@ApiOperation(value = "获取营销活动产品列表")
	@PostMapping("/getActivityProduct")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/getActivityProduct", userOperationType = 4, userOperationSummary = "获取营销活动产品列表")
	BaseResponse<IPage<ConferenceActivityProductBO>> getActivityProduct(
			@RequestBody ActivityProductVO activityProductVO) {
		logger.info("获取营销活动产品列表");
		return RespGenerator.returnOK(activityService.getActivityProduct(activityProductVO));
	}

	@ApiOperation(value = "获取营销活动客户清单")
	@PostMapping("/getActivityCustomerList")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/getActivityCustomerList", userOperationType = 4, userOperationSummary = "获取营销活动客户清单")
	BaseResponse<IPage<ConferenceActivityCustomerBO>> getActivityCustomerList(
			@RequestBody ActivityCustomerVO activityCustomerVO) {
		logger.info("获取营销活动客户清单");
		return RespGenerator.returnOK(activityService.getActivityCustomerList(activityCustomerVO));
	}

	@ApiOperation(value = "添加营销活动个人客户")
	@PostMapping("/addActivityPersonalCustomer")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/addActivityPersonalCustomer", userOperationType = 1, userOperationSummary = "添加营销活动个人客户")
	BaseResponse<Integer> addActivityPersonalCustomer(
			@RequestParam("activityId") @ApiParam(value = "营销活动id", required = true) String activityId,
			@RequestParam("personalFlag") @ApiParam(value = "是否为个人客户", required = true) Boolean personalFlag,
			@RequestBody @ApiParam(value = "客户信息数组", required = true) List<CustomerDetailVO> list) {
		logger.info("添加营销活动个人客户");
		return RespGenerator.returnOK(activityService.insertActivityPersonalCustomer(activityId, personalFlag, list));
	}

	@ApiOperation(value = "删除营销活动个人客户")
	@PostMapping("/deleteActivityPersonalCustomer")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/deleteActivityPersonalCustomer", userOperationType = 3, userOperationSummary = "删除营销活动个人客户")
	BaseResponse<Integer> deleteActivityPersonalCustomer(
			@RequestParam("activityId") @ApiParam(value = "营销活动ID", required = true) String activityId,
			@RequestParam("customerId") @ApiParam(value = "客户ID", required = true) String customerId) {
		logger.info("添加营销活动个人客户");
		return RespGenerator.returnOK(activityService.deleteActivityPersonalCustomer(activityId, customerId));
	}

	@ApiOperation(value = "新增、修改营销活动信息")
	@PostMapping("/modifyActivity")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/modifyActivity", userOperationType = 5, userOperationSummary = "新增或修改营销活动信息")
	BaseResponse<String> modifyActivity(@RequestBody ActivityModifyVO activityModifyVO) {
		logger.info("新增、修改营销活动信息");
		return RespGenerator.returnOK(activityService.modifyActivity(activityModifyVO));
	}

	@ApiOperation(value = "获取客户分配情况列表")
	@GetMapping("/getDistributionCustomerList")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/getDistributionCustomerList", userOperationType = 4, userOperationSummary = "获取客户分配情况列表")
	BaseResponse<IPage<ConferenceActivityCustomerBO>> getDistributionCustomerList(
			@RequestParam("activityId") @ApiParam(value = "营销活动id", required = true) String activityId,
			@RequestParam("currentPage") @ApiParam(value = "起始页", required = true) Integer currentPage,
			@RequestParam("pageSize") @ApiParam(value = "每页数据量", required = true) Integer pageSize,
			@RequestParam(value = "distributionFlag", required = false) @ApiParam(value = "是否查询已分配客户,不传时默认查询所有") Boolean distributionFlag) {
		logger.info("获取客户分配情况列表");
		return RespGenerator.returnOK(
				activityService.getDistributionCustomerList(activityId, distributionFlag, currentPage, pageSize));
	}

	@ApiOperation(value = "保存分配客户信息")
	@PostMapping("/modifyDistributionCustomer")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/modifyDistributionCustomer", userOperationType = 1, userOperationSummary = "保存分配客户信息")
	BaseResponse<Integer> modifyDistributionCustomer(@RequestBody DistributionCustomerVO distributionCustomerVO) {
		logger.info("保存分配客户信息");
		return RespGenerator.returnOK(activityService.modifyDistributionCustomer(distributionCustomerVO));
	}

	@ApiOperation(value = "取消活动")
	@GetMapping("/cancelActivity")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/cancelActivity", userOperationType = 2, userOperationSummary = "取消活动")
	BaseResponse<Integer> cancelActivity(
			@RequestParam("activityId") @ApiParam(value = "营销活动id", required = true) String activityId) {
		logger.info("取消活动");
		return RespGenerator.returnOK(activityService.cancelActivity(activityId));
	}

	@ApiOperation(value = "删除活动")
	@GetMapping("/deleteActivity")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/deleteActivity", userOperationType = 3, userOperationSummary = "删除活动")
	BaseResponse<Integer> deleteActivity(
			@RequestParam("activityId") @ApiParam(value = "营销活动id", required = true) String activityId) {
		logger.info("删除活动");
		return RespGenerator.returnOK(activityService.deleteActivity(activityId));
	}

	@ApiOperation(value = "查询营销活动统计信息")
	@GetMapping("/getActivityStatistics")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/getActivityStatistics", userOperationType = 4, userOperationSummary = "查询营销活动统计信息")
	BaseResponse<ConferenceActivityStatisticsBO> getActivityStatistics(
			@RequestParam("activityId") @ApiParam(value = "营销活动id", required = true) String activityId) {
		logger.info("查询营销活动统计信息");
		return RespGenerator.returnOK(activityService.getActivityStatistics(activityId));
	}

	@ApiOperation(value = "查询营销活动本端用户信息")
	@GetMapping("/getActivityUser")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/getActivityUser", userOperationType = 4, userOperationSummary = "查询营销活动本端用户信息")
	BaseResponse<IPage<ConferenceActivityUserBO>> getActivityUser(ActivityUserVO activityUserVO) {
		logger.info("查询营销活动本端用户信息");
		return RespGenerator.returnOK(activityService.getActivityUser(activityUserVO));
	}

	@ApiOperation(value = "查询营销活动合作公司用户信息")
	@GetMapping("/getActivityCooperationUser")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/getActivityCooperationUser", userOperationType = 4, userOperationSummary = "查询营销活动合作公司用户信息")
	BaseResponse<IPage<ConferenceActivityUserBO>> getActivityCooperationUser(ActivityUserVO activityUserVO) {
		logger.info("查询营销活动合作公司用户信息");
		return RespGenerator.returnOK(activityService.getActivityCooperationUser(activityUserVO));
	}

	@ApiOperation(value = "获取大数据客户清单")
	@PostMapping("/getCustomerInventory")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/getCustomerInventory", userOperationType = 4, userOperationSummary = "获取营销活动大数据客户清单")
	BaseResponse<List<CustomerInventoryBO>> getCustomerInventory(
			@RequestParam("batch") @ApiParam(value = "获取批次", required = true) Integer batch,
			@RequestBody ActivityDetailVO activityDetailVO) {
		logger.info("获取大数据客户清单");
		return RespGenerator.returnOK(customerInventoryService.getActivityCustomerInventory(batch, activityDetailVO));
	}

	@ApiOperation(value = "推送客户")
	@PostMapping("/pushCustomer")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/pushCustomer", userOperationType = 1, userOperationSummary = "推送客户")
	BaseResponse<String> pushCustomer(
			@RequestParam("activityId") @ApiParam(value = "营销活动ID", required = true) String activityId,
			@RequestBody CustomerDetailVO customer) {
		logger.info("推送客户");
		return RespGenerator.returnOK(activityService.pushCustomer(activityId, customer));
	}

	@ApiOperation(value = "电话联系客户")
	@PostMapping("/contactCustomer")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/contactCustomer", userOperationType = 2, userOperationSummary = "电话联系客户")
	BaseResponse<Integer> contactCustomer(
			@RequestParam("activityId") @ApiParam(value = "营销活动ID", required = true) String activityId,
			@RequestBody CustomerDetailVO customer) {
		logger.info("电话联系客户");
		return RespGenerator.returnOK(activityService.contactCustomer(activityId, customer));
	}

	@ApiOperation(value = "参加营销活动")
	@GetMapping("/joinActivity")
	@MyLog(systemFunctionName = "营销活动", systemFunctionUrl = "/activityController/joinActivity", userOperationType = 2, userOperationSummary = "参加营销活动")
	BaseResponse<Integer> joinActivity(
			@RequestParam("activityId") @ApiParam(value = "营销活动ID", required = true) String activityId,
			@RequestParam("userId") @ApiParam(value = "用户ID", required = true) String userId) {
		logger.info("参加营销活动");
		return RespGenerator.returnOK(activityService.joinActivity(userId, activityId));
	}

	/**
	 * 接收营销活动信息
	 * 
	 * @param activityAcception
	 * @return
	 */
	@PostMapping("/acceptionActivity")
	@ApiIgnore
	BaseResponse<Integer> acceptionActivity(@RequestBody ActivityAcceptionVO activityAcception) {
		logger.info("接收营销活动信息");
		return RespGenerator.returnOK(activityService.acceptionActivity(activityAcception));
	}
}
